package intf

import (
	"sync"
)

var cmdMap = map[string]Cmd{}
var rw = &sync.RWMutex{}

func Register(cmd Cmd) {
	rw.Lock()
	defer rw.Unlock()

	_, ok := cmdMap[cmd.Name()]
	if ok {
		panic("cmd:" + cmd.Name() + " duplicate")
	}

	cmdMap[cmd.Name()] = cmd
}

func Get(cmd string) Cmd {
	rw.RLock()
	defer rw.RUnlock()

	return cmdMap[cmd]
}
